package com.zw.knowlege.mapper;

import com.zw.knowlege.pojo.CollectRecordPojo;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * @Author xtyu
 * @Date 2022/5/11
 * @description 收藏记录
 */
public interface CollectRecordMapper {
    /**
     * 收藏记录
     * @return
     */
    @Insert("insert into woa_collect_record(userid, recordid, collecttime, type)\n" +
            "values(#{userid,jdbcType=VARCHAR}," +
                   "#{recordid,jdbcType=VARCHAR}," +
                   "#{collecttime,jdbcType=TIMESTAMP}," +
                   "#{type,jdbcType=VARCHAR})")
    int collectOneExperience(CollectRecordPojo collectRecordPojo);

    /**
     * 查询我的收藏
     * @param userId
     * @return
     */
    @Select("select userid,recordid,collecttime,type from woa_collect_record where userid=#{userId,jdbcType=VARCHAR}")
    List<CollectRecordPojo> queryMyCollectRecord(@Param("userId") String userId);

    /**
     * 取消或移除某条收藏的记录
     * @param userid
     * @param recordid
     * @return
     */
    @Delete("delete from woa_collect_record where userid=#{userid,jdbcType=VARCHAR} and recordid=#{recordid,jdbcType=VARCHAR}")
    int cancelCollectExperience(@Param("userid") String userid, @Param("recordid") String recordid);
    /**
     * 是否收藏
     * @param userid
     * @param recordid
     * @return
     */
    @Select("select count(1) from woa_collect_record where userid=#{userid,jdbcType=VARCHAR} and recordid=#{recordid,jdbcType=VARCHAR}")
    int isCollect(@Param("userid") String userid, @Param("recordid") String recordid);
}
